﻿using FarmSmartSleep.Common.Domain.EarTage;
using FarmSmartSleep.Common.Dtos;
using FarmSmartSleep.Common.Infrastructure;
using MediatR;

namespace FarmSmartSleep.Organ.API.Application.EarsCommands
{
    public class LambBirthdayStatusHander : IRequestHandler<LambBirthdayStatusCommand, ResultT<LambBirthdayStatus>>
    {

        private readonly ILogger<LambBirthdayStatusHander> logger;
        private readonly IBaseRepository<LambBirthdayStatus> birthdayStatusRepository;

        public LambBirthdayStatusHander(ILogger<LambBirthdayStatusHander> logger, IBaseRepository<LambBirthdayStatus> birthdayStatusRepository)
        {
            this.logger = logger;
            this.birthdayStatusRepository = birthdayStatusRepository;
        }
        /// <summary>
        /// 获取产羔出生状态
        /// </summary>
        /// <param name="request">获取产羔出生状态请求对象</param>
        /// <param name="cancellationToken"></param>
        /// <returns>获取产羔出生状态响应对象</returns>
        public async Task<ResultT<LambBirthdayStatus>> Handle(LambBirthdayStatusCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var result = new ResultT<LambBirthdayStatus>();
                result.Data =  birthdayStatusRepository.GetAll().ToList();
                logger.LogInformation("获取产羔出生状态方法调用成功");
                return result;
            }
            catch (Exception ex )
            {
                logger.LogError("获取产羔出生状态方法调用出错" + ex);
                throw;
            }
        }
    }
}
